<?php

namespace Helper\Model;

use Common\Model\BaseModel;

class SettingModel extends BaseModel
{
    public function getByKey($key) {
        $setting = D('Setting')->getByK($key);
        return unserialize($setting['v']);
    }

    public function updateActivity()
    {
        $activity = D('Setting')->getByK('activity');
        if (empty($activity)) {
            $activity = [
                'k' => 'activity',
                'v' => [
                    'all' => 1,    
                ]
            ];
            $activity['v'] = serialize($activity['v']);
            D('Setting')->add($activity);
        } else {
            $v = unserialize($activity['v']);
            $v['all'] += 1;
            D('Setting')->where(['k' => 'activity'])->setField('v', serialize($v));
        }
        
        return true;
        
    }
}
